﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Rio.Framework.Pages.Manager;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using NetBay.Core.BusinessEntities.Workflow;
using Rio.Framework.Pages.AppCode.Extensions;

namespace Rio.Framework.Pages.AppCode.Helpers.Utils
{
    public class WorkflowInstanceGridViewStyleSelector : StyleSelector
    {
        #region Methods

        public override Style SelectStyle(object item, DependencyObject container)
        {
            WorkflowInstance instance;
            bool isRead = false;
            WorkflowState state = WorkflowState.None;

            if (item is WorkflowInstance)
            {
                instance = item as WorkflowInstance;
                isRead = instance.IsRead;
                state = instance.State;
            }
            else
            {
                instance = ((ProxyBase<WorkflowInstance>)item).InnerItem;
                isRead = instance.IsRead;
                state = instance.State;
            }

            var style = new Style(typeof(GridViewRow));

            //Apply read style
            style.Setters.Add(isRead
                                  ? new Setter(Control.FontWeightProperty, FontWeights.Normal)
                                  : new Setter(Control.FontWeightProperty, FontWeights.Bold));

            ////Apply read style
            //style.Setters.Add(instance.HasChild
            //                      ? new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.DarkGray))
            //                      : new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.White)));

            if (WorkflowManager.WorkflowStatesInfos != null)
                style.Setters.Add(new Setter(Control.ForegroundProperty, new SolidColorBrush(WorkflowManager.WorkflowStatesInfos[state].GetColor())));

            return style;
        }


        #endregion Methods
    }


}